<html>
<head>
<title>Smarty Tag Translator</title>
<script SRC="../Shared/MM/Scripts/CMN/quickString.js"></SCRIPT>
<SCRIPT SRC="../Shared/Common/Scripts/dwscripts.js"></SCRIPT>
<SCRIPT SRC="TransData.js"></SCRIPT>
<SCRIPT SRC="TMCallback.js"></SCRIPT>
<SCRIPT SRC="Translator.js"></SCRIPT>
<SCRIPT SRC="TranslationManager.js"></SCRIPT>
<script language="JavaScript">
// *************** GLOBALS VARS *****************

var SERVER_MODEL_NAME = "Smarty";
var SERVER_MODEL_FOLDER = "Smarty";
var TRANSLATOR_CLASS  = "Smarty";
var TRANSLATOR_NAME   = SERVER_MODEL_NAME;

var SUCCESS_MARKER    = "<!-- MMDW:success -->";

var BEGIN_LOCK        = "<mm:beginlock translatorClass=\"MM_LIVE_DATA\" type=\"" + TRANSLATOR_CLASS + "\" orig=\"%s\">";
var END_LOCK          = "<mm:endlock>";
var TRANSLATED_ATTR   = "mmvisible=false";


// Specify which tags are jsp
var prefixArray = new Array();
prefixArray[0] = "foreach";

var debugTranslator   = false;


var liveDebugTranslator   = false;

/**
 * define smarty delimiters
*/

var LDELIM = "{{";
var RDELIM = "}}";


function getTranslatorInfo()
{
	var returnArray = new Array(6);
  returnArray[0] = TRANSLATOR_CLASS;   // The TRANSLATOR_CLASS
  returnArray[1] = TRANSLATOR_NAME;    // The title
  returnArray[2] = "0" 				   // The number of extensions
  returnArray[3] = "1" 		   	   // Extensions - indicate that we run on any
									   // extension for the JSP document type
									   // as defined in MMDocumentTypes.xml
  returnArray[4] = LDELIM+"";   // The number of expressions
  returnArray[5] = "byString";         // Run if doc contains expr
  returnArray[6] = "50";               // priority order to apply translator

  return returnArray

}



function translateMarkup(docNameStr, siteRootStr, inStr)
{
  var outStr = "";

  var serverModel = "";
  if (dw.getDocumentDOM())
  {
    serverModel = dw.getDocumentDOM().serverModel.getFolderName();
    if (serverModel == "")
    {
      serverModel = dw.getDocumentDOM().getServerModelFolderNameFromDoc();
    }
  }

  
  //alert("serverModel:"+serverModel )
  
  
  if (serverModel == SERVER_MODEL_FOLDER &&
      inStr.length > 0)
  {

    if (debugTranslator)
    {
      if (dwscripts.IS_MAC)
        DWfile.write( macBeforeFileName, inStr );
      else
        DWfile.write( winBeforeFileName, inStr );
    }

    outStr = miniTranslateMarkup(docNameStr, siteRootStr, inStr);

    // update Server Behavior list
    dw.serverBehaviorInspector.findAllServerBehaviors();

    if (debugTranslator)
    {
      if (dwscripts.IS_MAC)
        DWfile.write( macAfterFileName, outStr );
      else
        DWfile.write( winAfterFileName, outStr );
    }

  }

  return outStr;
}

//--------------------------------------------------------------------
// FUNCTION:
//   miniTranslateMarkup
//
// DESCRIPTION:
//   This function translates the given string.  It is broken out
//   so that other functions can call the translator.
//
// ARGUMENTS:
//   docNameStr - string - URL of the document to be translated
//   siteRootStr - string - URL of the site root
//   inStr - string - the contents of the document
//
// RETURNS:
//   string
//--------------------------------------------------------------------

function miniTranslateMarkup(docNameStr, siteRootStr, inStr)
{
  var outStr = "";
  //alert('module pass! begin translate')
  // translate
  if (inStr.indexOf(LDELIM) != -1)
  {
    var TM = new TranslationManager(TRANSLATOR_CLASS, SERVER_MODEL_FOLDER, "");
    TM.serverModelAlwaysCheckTag = myAlwaysCheckTag;
    TM.serverModelAlwaysCheckAttribute = myAlwaysCheckAttribute;
    //TM.defaultDirectiveTag = "MM_JSPSCRIPT";
    outStr = TM.translate(inStr);
  }

  return outStr;
}


//--------------------------------------------------------------------
// FUNCTION:
//   myAlwaysCheckTag
//
// DESCRIPTION:
//   This function is called by the translation manager to determine
//   if the given tag should be checked for dynamic info.
//
// ARGUMENTS:
//   tagName - string - the name of the tag to check
//
// RETURNS:
//   boolean
//--------------------------------------------------------------------

function myAlwaysCheckTag(tagName)
{
  return (tagName.substr(0, 4) == "foreach");
}


//--------------------------------------------------------------------
// FUNCTION:
//   myAlwaysCheckAttribute
//
// DESCRIPTION:
//   This function is called by the translation manager to determine
//   if the given attribute code should be checked for dynamic info.
//
// ARGUMENTS:
//   code - string - the code to check
//
// RETURNS:
//   boolean
//--------------------------------------------------------------------

function myAlwaysCheckAttribute(code)
{
  var result = code.indexOf("{{") != -1 ;
  return result;
}
</script>
</head>
<body>
</body>
</html>
